<template>
	<view class="container">
		<view class="content">
			<view class="title">
				<title class="title-1">交易金额</title>
				<view style="display: flex;justify-content: center;">
					<title style="width: 90%;display: flex;flex-direction: row;justify-content: space-between;">
						<title style="color: #fff;font-size: 60rpx;">
							{{list.txnAmt || ""}}
						</title>
						<title style="">
							<img style="max-width: 90rpx;max-height: 90rpx;border-radius: 50rpx;"
								src="../../static/transaction.png" alt="" />
						</title>
					</title>
				</view>
			</view>
			<view class="merchan-data-1">
				<uv-line color="#eceef2"></uv-line>
			</view>
			<view style="display: flex;justify-content: center;margin-top: 30rpx;">
				<title style="width: 90%;display: flex;flex-direction: row;justify-content: space-between;">
					<title style="color: #fff;font-size: 25rpx;">
						{{list.txnTime || ""}}
					</title>
					<title style="color: #fff;font-size: 25rpx;">
						交易时间
					</title>
				</title>
			</view>
		</view>
		<view class="merchantList">
			<view class="merchan">
				<view style="display: flex;justify-content: center;margin-top: 30rpx;">
					<title style="width: 90%;display: flex;flex-direction: row;justify-content: space-between;">
						<title style="display: flex;flex-direction: column;">
							<title style="color: #999999;font-size: 25rpx;margin-top: 15rpx;">
								订单号
							</title>
							<title style="color: #242f66;font-size: 30rpx;">
								{{list.merOrderNo || ""}}
							</title>
						</title>
						<title style="">
							<img style="max-width: 90rpx;max-height: 90rpx;" src="../../static/ordernumber.png"
								alt="" />
						</title>
					</title>
				</view>
				<view style="display: flex;justify-content: center;margin-top: 30rpx;">
					<title style="width: 90%;display: flex;flex-direction: row;justify-content: space-between;">
						<title style="display: flex;flex-direction: column;">
							<title style="color: #999999;font-size: 25rpx;margin-top: 15rpx;">
								支付方式
							</title>
							<title style="color: #242f66;font-size: 30rpx;">
								<text v-if="list.payType == '1'">银行卡</text>
								<text v-if="list.payType == '2'">支付宝</text>
								<text v-if="list.payType == '3'">微信</text>
								<text v-if="list.payType == '4'">银联二维码</text>
								<text v-if="list.payType == '5'">数币</text>
								<text v-if="list.payType == '6'">现金</text>
								<text v-if="list.payType == '0'">未知</text>
							</title>
						</title>
						<title style="">
							<img style="max-width: 90rpx;max-height: 90rpx;" src="../../static/paymentmethod.png"
								alt="" />
						</title>
					</title>
				</view>
				<view style="display: flex;justify-content: center;margin-top: 30rpx;">
					<title style="width: 90%;display: flex;flex-direction: row;justify-content: space-between;">
						<title style="display: flex;flex-direction: column;">
							<title style="color: #999999;font-size: 25rpx;margin-top: 15rpx;">
								支付状态
							</title>
							<title style="color: #242f66;font-size: 30rpx;">
								<text style="color: #437c43;" v-if="list.status == 'S'">交易成功</text>
								<text style="color: #ff5353;" v-if="list.status == 'E'">交易失败</text>
								<text style="color: #e4cc68;" v-if="list.status == 'T'">处理中</text>
								<text style="color: #ffbf68;" v-if="list.status == 'F'">退款申请</text>
								<text style="color: #626eff;" v-if="list.status == 'C'">已撤销</text>
							</title>
						</title>
						<title style="">
							<img style="max-width: 90rpx;max-height: 90rpx;" src="../../static/statetransaction.png"
								alt="" />
						</title>
					</title>
				</view>
				<view style="display: flex;justify-content: center;margin-top: 30rpx;">
					<title style="width: 90%;display: flex;flex-direction: row;justify-content: space-between;">
						<title style="display: flex;flex-direction: column;">
							<title style="color: #999999;font-size: 25rpx;margin-top: 15rpx;">
								退款金额
							</title>
							<title style="color: #242f66;font-size: 30rpx;">
								{{list.refundAmt || 0}}
							</title>
						</title>
						<title style="">
							<img style="max-width: 90rpx;max-height: 90rpx;" src="../../static/refundMoney.png"
								alt="" />
						</title>
					</title>
				</view>
			</view>
			<view class="button-wrap" v-if="list.status == 'S' && list.orderType == 'PAY'">
				<!-- 退款申请 -->
				<button class="button-login" @click="refundApplication">
					<text class="wx-login loginText1">退款申请</text>
				</button>
			</view>
			<view class="button-wrap" v-if="list.status == 'T'">
				<!-- 状态查询 -->
				<button class="button-login" @click="paymentStatus">
					<text class="wx-login loginText1">支付状态查询</text>
				</button>
			</view>
		</view>

		<uv-popup ref="popup" mode="bottom" :closeOnClickOverlay="false" :closeable="true" :round="10" @change="change">
			<view style="display: flex;justify-content: center;">
				<view style="height: 500rpx;width: 90%;margin-top: 35rpx;">
					<title style="color: #242f66;font-size: 30rpx;">
						退款金额
					</title>
					<view class="text" style="margin-bottom: 10rpx;">
						<uv-input v-model="fenecList.refundAmt" border="surround" placeholder="请输入退款金额"
							suffixIconStyle="color: #909399" fontSize="24rpx" color="#242f66">
						</uv-input>
					</view>
					<title style="color: #909399;font-size: 20rpx;margin-top: 20rpx;">
						提示：退款金额不得高于交易金额
					</title>
					<view class="button-wrap">
						<!-- 提交退款申请 -->
						<button class="button-login" @click="submitRefund">
							<text class="wx-login loginText1">提交退款申请</text>
						</button>
					</view>
				</view>
			</view>
		</uv-popup>
	</view>
</template>

<script>
	import {
		refund
	} from "../../network/transaction.js"
	export default {
		data() {
			return {
				list: {},
				fenecList: {
					srcMerOrderNo: "",
					merNo: "",
				},
				statusList: {}
			}
		},
		onLoad(e) {
			const arr = uni.getStorageSync('listData')
			this.list = JSON.parse(decodeURIComponent(e.item))
			this.fenecList.srcMerOrderNo = this.list.merOrderNo
			this.fenecList.merNo = arr.merNo
			console.log(this.list)
			// this.merchantList()
		},
		methods: {
			refundApplication() {
				this.$refs.popup.open();
			},
			change(e) {
				console.log('弹窗状态改变：', e);
			},
			submitRefund() {
				if (this.fenecList.refundAmt <= this.list.txnAmt) {
					this.refundArr()
				} else {
					uni.showToast({
						title: "退款金额不得大于交易金额",
						icon: 'none',
						duration: 2000
					})
				}

			},
			refundArr() {
				refund(this.fenecList).then(res => {
					const code = res.data.code;
					if (code == "000000") {
						uni.showToast({
							title: "已提交退款申请",
							icon: 'success',
							duration: 2000
						})
						setTimeout(() => {
							wx.navigateTo({
								url: '/pages/transaction/index'
							})
						}, 2000)
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 2000
						})
					}
				})
			},
			paymentStatus() {
				const arr = {
					orderType: this.list.orderType,
					merOrderNo: this.list.merOrderNo,
					merNo: this.fenecList.merNo,
				}
				refund(arr).then(res => {
					const code = res.data.code;
					if (code == "000000") {
						uni.showToast({
							title: "查询成功",
							icon: 'success',
							duration: 2000
						})
						setTimeout(() => {
							wx.navigateTo({
								url: '/pages/transaction/index'
							})
						}, 2000)
					} else {
						uni.showToast({
							title: "查询失败",
							icon: 'none',
							duration: 2000
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		height: 100vh;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		/* justify-content: center; */
		flex-direction: column;
	}

	.content {
		width: 100%;
		height: 20%;
		background-image: url('../../static/homePage.png');
		background-size: 100% 100%;
	}

	.merchantList {
		height: 80%;
		width: 100%;
	}

	.merchan {
		font-weight: bold;
		color: #242f66;
	}

	.ArrList {
		display: flex;
		align-items: center;
		/* justify-content: center; */
		flex-direction: column;
	}

	.List {
		background: #fff;
		height: 320rpx;
		width: 85%;
		border-radius: 20rpx;
		margin-top: 5%;
	}

	.merchan-data {
		display: flex;
	}

	.imgData {
		width: 100rpx;
		height: 100rpx;
		border-radius: 20rpx;
		background-image: url('../../static/index.png');
		background-size: 100% 100%;
		margin: 40rpx 50rpx 20rpx 50rpx;
	}

	.image {
		max-width: 100rpx;
		max-height: 100rpx;
	}

	.text {
		display: flex;
		flex-flow: column;
	}

	.merchan-data-1 {
		display: flex;
		justify-content: center;
	}

	/deep/.uv-line {
		width: 90% !important;
	}

	.merchan-data-2 {
		margin-top: 8%;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.title-1 {
		color: #fff;
		margin: 20px 0px 5px 20px;
		font-size: 30rpx;
		display: grid;
	}

	.button-wrap {
		margin-top: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}

	.button-login {
		width: 90%;
		height: 110rpx;
		border-radius: 20rpx;
		background: #222d65;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		bottom: 100rpx;
	}

	.loginText1 {
		margin-left: 6rpx;
		color: #fff;
		font-size: 35rpx;
	}

	.text {
		height: 100rpx;
		margin-top: 20rpx;
		border-radius: 11px;
		border: 1px solid #dfe3ed;
	}
</style>